<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>${book == null ? '添加图书' : '编辑图书'} - 万万书城管理端</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .header {
            background-color: #333;
            color: white;
            padding: 20px;
            text-align: center;
        }
        .nav {
            background-color: #555;
            overflow: hidden;
        }
        .nav a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }
        .nav a:hover {
            background-color: #777;
        }
        .content {
            padding: 20px;
            max-width: 800px;
            margin: 0 auto;
        }
        .form-container {
            background-color: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        h2 {
            margin-top: 0;
            color: #333;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }
        input[type="text"],
        input[type="number"],
        select,
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            box-sizing: border-box;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
        .form-actions {
            margin-top: 30px;
        }
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-right: 10px;
        }
        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }
        .btn-primary:hover {
            background-color: #45a049;
        }
        .btn-secondary {
            background-color: #f1f1f1;
            color: #333;
        }
        .btn-secondary:hover {
            background-color: #e5e5e5;
        }
        .error {
            color: #f44336;
            font-size: 14px;
            margin-top: 5px;
        }
        .message {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 4px;
            font-weight: bold;
        }
        .error-message {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>万万书城 - 管理端</h1>
    </div>
    
    <div class="nav">
        <a href="admin?action=list">图书管理</a>
        <a href="logout" style="float: right;">退出登录</a>
    </div>
    
    <div class="content">
        <div class="form-container">
            <h2>${book == null ? '添加图书' : '编辑图书'}</h2>
            
            <!-- 错误提示 -->
            <c:if test="${not empty errorMessage}">
                <div class="message error-message">${errorMessage}</div>
            </c:if>
            
            <form action="admin" method="post">
                <input type="hidden" name="action" value="${book == null ? 'save' : 'update'}">
                <c:if test="${not empty book}">
                    <input type="hidden" name="id" value="${book.id}">
                </c:if>
                <c:if test="${not empty keyword}">
                    <input type="hidden" name="keyword" value="${keyword}">
                </c:if>
                
                <div class="form-group">
                    <label for="title">书名 *</label>
                    <input type="text" id="title" name="title" value="${book != null ? book.title : ''}" required>
                </div>
                
                <div class="form-group">
                    <label for="author">作者 *</label>
                    <input type="text" id="author" name="author" value="${book != null ? book.author : ''}" required>
                </div>
                
                <div class="form-group">
                    <label for="price">价格 *</label>
                    <input type="number" id="price" name="price" step="0.01" min="0.01" value="${book != null ? book.price : ''}" required>
                </div>
                
                <div class="form-group">
                    <label for="category">分类 *</label>
                    <select id="category" name="category" required>
                        <option value="">请选择分类</option>
                        <c:forEach items="${categories}" var="category">
                            <option value="${category.name}" ${book != null && book.category == category.name ? 'selected' : ''}>${category.name}</option>
                        </c:forEach>
                    </select>
                </div>
                
                <div class="form-group">
                    <label for="description">描述</label>
                    <textarea id="description" name="description">${book != null ? book.description : ''}</textarea>
                </div>
                
                <div class="form-group">
                    <label for="stock">库存数量 *</label>
                    <input type="number" id="stock" name="stock" min="0" value="${book != null ? book.stock : '0'}" required>
                </div>
                
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">${book == null ? '添加' : '保存'}</button>
                    <a href="admin?action=list" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </div>
    </div>
</body>
</html>